<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>lib/strutil/replace.c</title>
<meta name='robots' content='noindex,nofollow' />
<meta name='generator' content='GLOBAL-6.5.7' />
<meta http-equiv='Content-Style-Type' content='text/css' />
<link rel='stylesheet' type='text/css' href='../style.css' />
</head>
<body>
<!-- beginning of fixed guide -->
<div id='guide'><ul>
<li><a href='#L45'><img class='icon' src='../icons/first.png' alt='[^]' /></a></li>
<li><a href='#L72'><img class='icon' src='../icons/last.png' alt='[v]' /></a></li>
<li><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a></li>
<li><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a></li>
<li><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a></li>
<li class='standout'><span><a href='../files/lib.html'>lib</a>/<a href='../files/lib--strutil.html'>strutil</a>/replace.c</span></li>
</ul></div>
<!-- end of fixed guide -->
<a id='TOP' name='TOP'></a><h2 class='header'><a href='../mains.html'>root</a>/<a href='../files/lib.html'>lib</a>/<a href='../files/lib--strutil.html'>strutil</a>/replace.c</h2>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><a href='#L45'><img class='icon' src='../icons/first.png' alt='[first]' /></a><a href='#L72'><img class='icon' src='../icons/last.png' alt='[last]' /></a><img class='icon' src='../icons/n_top.png' alt='[top]' /><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+1 lib/strutil/replace.c'  /> */</em>
<hr />
<h2 class='header'>DEFINITIONS</h2>
This source file includes following definitions.
<ol>
<li><a href='#L45' title='Defined at 45.'>str_ptr_array_join</a></li>
<li><a href='#L72' title='Defined at 72.'>str_replace_all</a></li>
</ol>
<hr />
<pre>
<a id='L1' name='L1'></a>   1 <em class='comment'>/*</em>
<a id='L2' name='L2'></a>   2 <em class='comment'>   Functions for replacing substrings in strings.</em>
<a id='L3' name='L3'></a>   3 <em class='comment'></em>
<a id='L4' name='L4'></a>   4 <em class='comment'>   Copyright (C) 2013-2020</em>
<a id='L5' name='L5'></a>   5 <em class='comment'>   Free Software Foundation, Inc.</em>
<a id='L6' name='L6'></a>   6 <em class='comment'></em>
<a id='L7' name='L7'></a>   7 <em class='comment'>   Written by:</em>
<a id='L8' name='L8'></a>   8 <em class='comment'>   Slava Zanko &lt;slavazanko@gmail.com&gt;, 2013;</em>
<a id='L9' name='L9'></a>   9 <em class='comment'></em>
<a id='L10' name='L10'></a>  10 <em class='comment'>   This file is part of the Midnight Commander.</em>
<a id='L11' name='L11'></a>  11 <em class='comment'></em>
<a id='L12' name='L12'></a>  12 <em class='comment'>   The Midnight Commander is free software: you can redistribute it</em>
<a id='L13' name='L13'></a>  13 <em class='comment'>   and/or modify it under the terms of the GNU General Public License as</em>
<a id='L14' name='L14'></a>  14 <em class='comment'>   published by the Free Software Foundation, either version 3 of the License,</em>
<a id='L15' name='L15'></a>  15 <em class='comment'>   or (at your option) any later version.</em>
<a id='L16' name='L16'></a>  16 <em class='comment'></em>
<a id='L17' name='L17'></a>  17 <em class='comment'>   The Midnight Commander is distributed in the hope that it will be useful,</em>
<a id='L18' name='L18'></a>  18 <em class='comment'>   but WITHOUT ANY WARRANTY; without even the implied warranty of</em>
<a id='L19' name='L19'></a>  19 <em class='comment'>   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</em>
<a id='L20' name='L20'></a>  20 <em class='comment'>   GNU General Public License for more details.</em>
<a id='L21' name='L21'></a>  21 <em class='comment'></em>
<a id='L22' name='L22'></a>  22 <em class='comment'>   You should have received a copy of the GNU General Public License</em>
<a id='L23' name='L23'></a>  23 <em class='comment'>   along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</em>
<a id='L24' name='L24'></a>  24 <em class='comment'> */</em>
<a id='L25' name='L25'></a>  25 
<a id='L26' name='L26'></a>  26 <em class='sharp'>#include</em> &lt;config.h&gt;
<a id='L27' name='L27'></a>  27 
<a id='L28' name='L28'></a>  28 <em class='sharp'>#include</em> "<a href='lib--global.h.html'>lib/global.h</a>"
<a id='L29' name='L29'></a>  29 <em class='sharp'>#include</em> "<a href='lib--strescape.h.html'>lib/strescape.h</a>"
<a id='L30' name='L30'></a>  30 <em class='sharp'>#include</em> "<a href='lib--strutil.h.html'>lib/strutil.h</a>"
<a id='L31' name='L31'></a>  31 
<a id='L32' name='L32'></a>  32 <em class='comment'>/*** global variables ****************************************************************************/</em>
<a id='L33' name='L33'></a>  33 
<a id='L34' name='L34'></a>  34 <em class='comment'>/*** file scope macro definitions ****************************************************************/</em>
<a id='L35' name='L35'></a>  35 
<a id='L36' name='L36'></a>  36 <em class='comment'>/*** file scope type declarations ****************************************************************/</em>
<a id='L37' name='L37'></a>  37 
<a id='L38' name='L38'></a>  38 <em class='comment'>/*** file scope variables ************************************************************************/</em>
<a id='L39' name='L39'></a>  39 
<a id='L40' name='L40'></a>  40 <em class='comment'>/* --------------------------------------------------------------------------------------------- */</em>
<a id='L41' name='L41'></a>  41 <em class='comment'>/*** file scope functions ************************************************************************/</em>
<a id='L42' name='L42'></a>  42 <em class='comment'>/* --------------------------------------------------------------------------------------------- */</em>
<a id='L43' name='L43'></a>  43 
<a id='L44' name='L44'></a>  44 <strong class='reserved'>static</strong> <strong class='reserved'>char</strong> *
<a id='L45' name='L45'></a>  45 <a href='../S/lib--strutil--replace.c.html#L110' title='Referred from 110 in lib/strutil/replace.c.'>str_ptr_array_join</a> (<strong class='reserved'>const</strong> <a href='../Y/GPtrArray.html' title='Multiple used in 61 places.'>GPtrArray</a> * <a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>)
     <em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><a href='#L72'><img class='icon' src='../icons/right.png' alt='[next]' /></a><img class='icon' src='../icons/n_first.png' alt='[first]' /><a href='#L72'><img class='icon' src='../icons/last.png' alt='[last]' /></a><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+45 lib/strutil/replace.c'  /> */</em>
<a id='L46' name='L46'></a>  46 <em class='brace'>{</em>
<a id='L47' name='L47'></a>  47     <a href='../Y/GString.html' title='Multiple used in 219 places.'>GString</a> *<a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a>;
<a id='L48' name='L48'></a>  48     <a href='../Y/guint.html' title='Multiple used in 29 places.'>guint</a> <a href='../Y/i.html' title='Multiple used in 2441 places.'>i</a>;
<a id='L49' name='L49'></a>  49 
<a id='L50' name='L50'></a>  50     <a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a> = <a href='../Y/g_string_sized_new.html' title='Multiple used in 50 places.'>g_string_sized_new</a> (32);
<a id='L51' name='L51'></a>  51     <strong class='reserved'>for</strong> (<a href='../Y/i.html' title='Multiple used in 2441 places.'>i</a> = 0; <a href='../Y/i.html' title='Multiple used in 2441 places.'>i</a> &lt; <a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>-&gt;<a href='../Y/len.html' title='Multiple used in 1086 places.'>len</a>; <a href='../Y/i.html' title='Multiple used in 2441 places.'>i</a>++)
<a id='L52' name='L52'></a>  52         <a href='../Y/g_string_append.html' title='Multiple used in 106 places.'>g_string_append</a> (<a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a>, <a href='../Y/g_ptr_array_index.html' title='Multiple used in 107 places.'>g_ptr_array_index</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/i.html' title='Multiple used in 2441 places.'>i</a>));
<a id='L53' name='L53'></a>  53 
<a id='L54' name='L54'></a>  54     <strong class='reserved'>return</strong> <a href='../Y/g_string_free.html' title='Multiple used in 150 places.'>g_string_free</a> (<a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a>, <a href='../Y/FALSE.html' title='Multiple used in 1594 places.'>FALSE</a>);
<a id='L55' name='L55'></a>  55 <em class='brace'>}</em>
<a id='L56' name='L56'></a>  56 
<a id='L57' name='L57'></a>  57 <em class='comment'>/* --------------------------------------------------------------------------------------------- */</em>
<a id='L58' name='L58'></a>  58 <em class='comment'>/*** public functions ****************************************************************************/</em>
<a id='L59' name='L59'></a>  59 <em class='comment'>/* --------------------------------------------------------------------------------------------- */</em>
<a id='L60' name='L60'></a>  60 <em class='comment'>/**</em>
<a id='L61' name='L61'></a>  61 <em class='comment'> * Replace all substrings 'needle' in string 'haystack' by 'replacement'.</em>
<a id='L62' name='L62'></a>  62 <em class='comment'> * If the 'needle' in the 'haystack' will be escaped by backslash,</em>
<a id='L63' name='L63'></a>  63 <em class='comment'> * then this occurrence isn't be replaced.</em>
<a id='L64' name='L64'></a>  64 <em class='comment'> *</em>
<a id='L65' name='L65'></a>  65 <em class='comment'> * @param haystack    string contains substrings for replacement</em>
<a id='L66' name='L66'></a>  66 <em class='comment'> * @param needle      string for search</em>
<a id='L67' name='L67'></a>  67 <em class='comment'> * @param replacement string for replace</em>
<a id='L68' name='L68'></a>  68 <em class='comment'> * @return newly allocated string with replaced substrings</em>
<a id='L69' name='L69'></a>  69 <em class='comment'> */</em>
<a id='L70' name='L70'></a>  70 
<a id='L71' name='L71'></a>  71 <strong class='reserved'>char</strong> *
<a id='L72' name='L72'></a>  72 <a href='../R/str_replace_all.html' title='Multiple referred from 8 places.'>str_replace_all</a> (<strong class='reserved'>const</strong> <strong class='reserved'>char</strong> *<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>, <strong class='reserved'>const</strong> <strong class='reserved'>char</strong> *<a href='../Y/needle.html' title='Multiple used in 31 places.'>needle</a>, <strong class='reserved'>const</strong> <strong class='reserved'>char</strong> *<a href='../Y/replacement.html' title='Multiple used in 5 places.'>replacement</a>)
     <em class='comment'>/* <a href='#L45'><img class='icon' src='../icons/left.png' alt='[previous]' /></a><img class='icon' src='../icons/n_right.png' alt='[next]' /><a href='#L45'><img class='icon' src='../icons/first.png' alt='[first]' /></a><img class='icon' src='../icons/n_last.png' alt='[last]' /><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+72 lib/strutil/replace.c'  /> */</em>
<a id='L73' name='L73'></a>  73 <em class='brace'>{</em>
<a id='L74' name='L74'></a>  74     <a href='../Y/size_t.html' title='Multiple used in 726 places.'>size_t</a> <a href='../Y/needle_len.html' title='Multiple used in 3 places.'>needle_len</a>;
<a id='L75' name='L75'></a>  75     <a href='../Y/GPtrArray.html' title='Multiple used in 61 places.'>GPtrArray</a> *<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>;
<a id='L76' name='L76'></a>  76     <strong class='reserved'>char</strong> *<a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a>;
<a id='L77' name='L77'></a>  77 
<a id='L78' name='L78'></a>  78     <a href='../Y/needle_len.html' title='Multiple used in 3 places.'>needle_len</a> = <a href='../Y/strlen.html' title='Multiple used in 281 places.'>strlen</a> (<a href='../Y/needle.html' title='Multiple used in 31 places.'>needle</a>);
<a id='L79' name='L79'></a>  79 
<a id='L80' name='L80'></a>  80     <a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a> = <a href='../Y/g_ptr_array_new.html' title='Multiple used in 29 places.'>g_ptr_array_new</a> ();
<a id='L81' name='L81'></a>  81 
<a id='L82' name='L82'></a>  82     <strong class='reserved'>while</strong> (<a href='../Y/TRUE.html' title='Multiple used in 1520 places.'>TRUE</a>)
<a id='L83' name='L83'></a>  83     <em class='brace'>{</em>
<a id='L84' name='L84'></a>  84         <strong class='reserved'>char</strong> *<a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a>;
<a id='L85' name='L85'></a>  85 
<a id='L86' name='L86'></a>  86         <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> = <a href='../D/strstr.html' title='Multiple defined in 2 places.'>strstr</a> (<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>, <a href='../Y/needle.html' title='Multiple used in 31 places.'>needle</a>);
<a id='L87' name='L87'></a>  87         <strong class='reserved'>if</strong> (<a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> == <a href='../Y/NULL.html' title='Multiple used in 5646 places.'>NULL</a>)
<a id='L88' name='L88'></a>  88         <em class='brace'>{</em>
<a id='L89' name='L89'></a>  89             <strong class='reserved'>if</strong> (*<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a> != '\0')
<a id='L90' name='L90'></a>  90                 <a href='../Y/g_ptr_array_add.html' title='Multiple used in 52 places.'>g_ptr_array_add</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/g_strdup.html' title='Multiple used in 444 places.'>g_strdup</a> (<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>));
<a id='L91' name='L91'></a>  91             <strong class='reserved'>break</strong>;
<a id='L92' name='L92'></a>  92         <em class='brace'>}</em>
<a id='L93' name='L93'></a>  93 
<a id='L94' name='L94'></a>  94         <strong class='reserved'>if</strong> (<a href='../S/lib--strutil--strescape.c.html#L243' title='Defined at 243 in lib/strutil/strescape.c.'>strutils_is_char_escaped</a> (<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>, <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a>))
<a id='L95' name='L95'></a>  95         <em class='brace'>{</em>
<a id='L96' name='L96'></a>  96             <strong class='reserved'>char</strong> *<a href='../Y/backslash.html' title='Multiple used in 4 places.'>backslash</a> = <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> - 1;
<a id='L97' name='L97'></a>  97 
<a id='L98' name='L98'></a>  98             <strong class='reserved'>if</strong> (<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a> != <a href='../Y/backslash.html' title='Multiple used in 4 places.'>backslash</a>)
<a id='L99' name='L99'></a>  99                 <a href='../Y/g_ptr_array_add.html' title='Multiple used in 52 places.'>g_ptr_array_add</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/g_strndup.html' title='Multiple used in 66 places.'>g_strndup</a> (<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>, <a href='../Y/backslash.html' title='Multiple used in 4 places.'>backslash</a> - <a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>));
<a id='L100' name='L100'></a> 100 
<a id='L101' name='L101'></a> 101             <a href='../Y/g_ptr_array_add.html' title='Multiple used in 52 places.'>g_ptr_array_add</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/g_strndup.html' title='Multiple used in 66 places.'>g_strndup</a> (<a href='../Y/backslash.html' title='Multiple used in 4 places.'>backslash</a> + 1, <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> - <a href='../Y/backslash.html' title='Multiple used in 4 places.'>backslash</a>));
<a id='L102' name='L102'></a> 102             <a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a> = <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> + 1;
<a id='L103' name='L103'></a> 103             <strong class='reserved'>continue</strong>;
<a id='L104' name='L104'></a> 104         <em class='brace'>}</em>
<a id='L105' name='L105'></a> 105         <strong class='reserved'>if</strong> (<a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> - <a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a> &gt; 0)
<a id='L106' name='L106'></a> 106             <a href='../Y/g_ptr_array_add.html' title='Multiple used in 52 places.'>g_ptr_array_add</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/g_strndup.html' title='Multiple used in 66 places.'>g_strndup</a> (<a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>, <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> - <a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a>));
<a id='L107' name='L107'></a> 107         <a href='../Y/g_ptr_array_add.html' title='Multiple used in 52 places.'>g_ptr_array_add</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/g_strdup.html' title='Multiple used in 444 places.'>g_strdup</a> (<a href='../Y/replacement.html' title='Multiple used in 5 places.'>replacement</a>));
<a id='L108' name='L108'></a> 108         <a href='../Y/haystack.html' title='Multiple used in 21 places.'>haystack</a> = <a href='../Y/needle_in_str.html' title='Multiple used in 10 places.'>needle_in_str</a> + <a href='../Y/needle_len.html' title='Multiple used in 3 places.'>needle_len</a>;
<a id='L109' name='L109'></a> 109     <em class='brace'>}</em>
<a id='L110' name='L110'></a> 110     <a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a> = <a href='../S/lib--strutil--replace.c.html#L45' title='Defined at 45 in lib/strutil/replace.c.'>str_ptr_array_join</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>);
<a id='L111' name='L111'></a> 111 
<a id='L112' name='L112'></a> 112     <a href='../Y/g_ptr_array_foreach.html' title='Multiple used in 25 places.'>g_ptr_array_foreach</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, (<a href='../Y/GFunc.html' title='Multiple used in 27 places.'>GFunc</a>) <a href='../Y/g_free.html' title='Multiple used in 1230 places.'>g_free</a>, <a href='../Y/NULL.html' title='Multiple used in 5646 places.'>NULL</a>);
<a id='L113' name='L113'></a> 113     <a href='../Y/g_ptr_array_free.html' title='Multiple used in 32 places.'>g_ptr_array_free</a> (<a href='../Y/str_splints.html' title='Multiple used in 13 places.'>str_splints</a>, <a href='../Y/TRUE.html' title='Multiple used in 1520 places.'>TRUE</a>);
<a id='L114' name='L114'></a> 114 
<a id='L115' name='L115'></a> 115     <strong class='reserved'>return</strong> <a href='../Y/return_str.html' title='Multiple used in 12 places.'>return_str</a>;
<a id='L116' name='L116'></a> 116 <em class='brace'>}</em>
<a id='L117' name='L117'></a> 117 
<a id='L118' name='L118'></a> 118 <em class='comment'>/* --------------------------------------------------------------------------------------------- */</em>
</pre>
<hr />
<a id='BOTTOM' name='BOTTOM'></a>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><a href='#L45'><img class='icon' src='../icons/first.png' alt='[first]' /></a><a href='#L72'><img class='icon' src='../icons/last.png' alt='[last]' /></a><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><img class='icon' src='../icons/n_bottom.png' alt='[bottom]' /><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+118 lib/strutil/replace.c'  /> */</em>
</body>
</html>
